package controller

import (
	"github.com/PhlexTheCharr/gofurry-cloud-service/apps/openlist/util/service"
	"github.com/PhlexTheCharr/gofurry-cloud-service/common"
	"github.com/gofiber/fiber/v2"
)

/*
 * @Desc: 支撑 OpenList 功能
 * @author: 慵狼小洛
 * @version: v1.0.0
 */

type utilApi struct{}

var UtilApi *utilApi

func init() {
	UtilApi = &utilApi{}
}

// @Summary 获取Logo图片
// @Schemes
// @Description 获取Logo图片
// @Tags Openlist-util
// @Accept json
// @Produce json
// @Success 200 {object} common.ResultData
// @Router /api/ol/util/getLogo [Get]
func (api *utilApi) GetLogo(c *fiber.Ctx) error {
	logoPath, err := service.GetUtilService().GetLogoService()
	if err != nil {
		return common.NewResponse(c).Error(err)
	}

	return c.SendFile(logoPath)
}

// @Summary 获取背景图片
// @Schemes
// @Description 获取背景图片
// @Tags Openlist-util
// @Accept json
// @Produce json
// @Success 200 {object} common.ResultData
// @Router /api/ol/util/getImage [Get]
func (api *utilApi) GetImage(c *fiber.Ctx) error {
	imagePath, err := service.GetUtilService().GetImageService(c)
	if err != nil {
		return common.NewResponse(c).Error(err)
	}

	return c.SendFile(imagePath)
}

// @Summary 获取随机金句
// @Schemes
// @Description 获取随机金句
// @Tags Openlist-util
// @Accept json
// @Produce json
// @Success 200 {object} common.ResultData
// @Router /api/ol/util/getSaying [Get]
func (api *utilApi) GetSaying(c *fiber.Ctx) error {
	saying, err := service.GetUtilService().GetSayingService()
	if err != nil {
		return common.NewResponse(c).Error(err)
	}
	c.Type("text/plain; charset=utf-8")
	return c.SendString(saying)
}
